<?php

namespace App\Http\Requests\Seller\Auth;

use App\Rules\PasswordRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

class ChangePasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
            'original_password'=>['required',function($attribute,$value,$fail){
                $pwd = Auth::guard('seller')->user()->password;
                if(Hash::check($value,$pwd)){
                    return true;
                }else{
                    $fail(':attribute不正确');
                }
            },'bail'],
            'password'=>['required','different:original_password',new PasswordRule,'confirmed','bail']
        ];
    }
    public function attributes()
    {
        return [
            'original_password'=>'原始密码',
            'password'=>'新密码',
            'password_confirmation'=>'确认密码'
        ];
    }
}
